#include "os/time.h"
#include "dbg/log.h"
#include <stdio.h>
#include <stdarg.h>

#ifdef WIN32

#include "win32/lean_windows.h"

void log(const char* message, ...)
{
	char time_buf[32];
	static Time start_time = Time::current();
	sprintf(time_buf, "%.4f ", Time::current() - start_time);

	OutputDebugString(time_buf);

	va_list args;
	va_start(args, message);

	const int buf_len = max(16, strlen(message)) * 3;
	char* buf = new char[buf_len];
	buf[buf_len-1] = 0;
	
	int result = vsnprintf(buf, buf_len-1, message, args);

	OutputDebugString(buf);
	delete[] buf;

	if (result == -1)
		OutputDebugString(" (message was truncated.)");

	OutputDebugString("\n");
}

#else

void log(const char* message)
{
	printf(message);
}

#endif
